<script>
	import unicore from '@/core/core.service.ts'
	import store from './store/index.ts'
	export default {
		onLaunch: function(param) {
			// #ifdef H5
			// this.$core.dom.loadScript('static/log.js').then(() => {
			// 	this.$core.log = new jyrslog('supply','h5','asddewadsf');
			// 	this.$core.log.sendLog('index');
			// })
			
			if (sessionStorage.getItem("store")) { // 刷新存储store //uni.setstoragesync
				this.$store.replaceState(
					Object.assign(this.$store.state, JSON.parse(sessionStorage.getItem("store")))
			  );
			}
			window.addEventListener("beforeunload", () => {
			  sessionStorage.setItem("store", JSON.stringify(this.$store.state));
			});
			window.addEventListener("pagehide", () => {
			  sessionStorage.setItem("store", JSON.stringify(this.$store.state));
			  if(unicore.env.iswxh5){
				  sessionStorage.setItem('iswxh5',1)
			  }
			});
			window.addEventListener("beforeunload", () => {
				sessionStorage.setItem("store", JSON.stringify(this.$store.state));
			})
			// #endif
			if (process.env.NODE_ENV == 'production' && process.env.VUE_APP_Vconsole == 'true') {
				this.$core.dom.loadScript("static/vconsole.min.js").then(() => {
					var vConsole = new VConsole();
				});
			}
			

		},
		onShow: function() {},
		onHide: function() {},
		methods: {
			isLogin(){
				let iswxh5 = unicore.env.iswxh5
				if (iswxh5) { // ios app 端标题异常，公众号标题异常
					let pagebody = document.getElementsByTagName('uni-app')[0]
					pagebody.setAttribute('class','iswxh5')
				}
				let token = store.state.common.token
				console.log(iswxh5,'iswxh5')
				// let route = this.$core.dom.window.location.hash
				let route = this.$core.dom.window.location.hash.replace(/\#/g,"")
				let routeArr = [ // 无需登录页面
					"/pages/login/indexty",
				]
				let notoken = routeArr.some((item)=>{
					return route.indexOf(item) !== -1;
			 	})
				if (notoken||iswxh5) {
					console.log('不跳登录')
					return ''
				}
				console.log(token,'token')
				if (!token&&process.env.NODE_ENV == 'production') {
					console.log('跳转登录')
					store.state.common.saveUrl = route
					uni.redirectTo({
						url:"/pages/login/indexty"
					})
				}
			},
			// 微信禁止调整字体大小
			handleFontSize() {
				WeixinJSBridge.invoke("setFontSizeCallback", {
					"fontSize": 0
				});
				WeixinJSBridge.on('menu:setfont', () => {
					WeixinJSBridge.invoke("setFontSizeCallback", {
						"fontSize": 0
					});
				})
			},
			
			//小程序进入首页  权限校验
			checkPermission(obj){
			  console.log("-------------checkPermission----------");
			  wx.getSetting({
			    success:function(res){
			      if (!res.authSetting['scope.userLocation']) {
			        console.log("-------------不满足scope.userLocation权限----------");
			        //申请授权
			        wx.authorize({
			          scope: 'scope.userLocation',
			          success() {
			            
			          }
			        })
			      }
			    }
			  })
			}

		},
		mounted() {
			this.checkPermission(this); 
			 
			//#ifdef MP-WEIXIN
			document.addEventListener('WeixinJSBridgeReady', () => {
				WeixinJSBridge.call('hideOptionMenu');

				// 微信禁止调整字体大小
				if (typeof WeixinJSBridge === "object" && typeof WeixinJSBridge.invoke === "function") {
					this.handleFontSize()
				} else {
					if (document.addEventListener) {
						document.addEventListener("WeixinJSBridgeReady", this.handleFontSize(), false)
					} else if (document.attachEvent) {
						document.attachEvent("WeixinJSBridgeReady", this.handleFontSize())
						document.attachEvent("onWeixinJSBridgeReady", this.handleFontSize())
					}
				}

			})
			// #endif
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	/*兼容小程序背景色样式 */
	page {
		font-family: PingFangSC-Regular;
		height: 100%;
		width: 100%;
	}
	uni-page-head {
		height: 0;
		display: none;
	}
	uni-page-wrapper {
		height: 100% !important;
	}
	/*兼容h5背景色样式 ios 滑动不流畅问题*/
	uni-page-body {
		background: #EBEBEB;
		overflow-y: scroll;
		-webkit-overflow-scrolling: touch;
		font-family: "思源黑体";
		-webkit-text-size-adjust: 100% !important; // 禁止ios 微信端字体调整
		text-size-adjust: 100% !important;
		-moz-text-size-adjust: 100% !important;
	}
	uni-button[type=primary]{
		background-color: #0057B0;
	}
	.uni-picker-container{position: relative;} //去掉fixed定位 ios滑动异常
	uni-input,uni-textarea{ // 有坑  预约页面图片异常，解决ios输入白屏
		// transform: translateZ(0rpx);
		// -webkit-transform: translateZ(0rpx);
		// -moz-transform: translateZ(0rpx);
		line-height: normal;
	}
	uni-radio .uni-radio-input{
		width: 32rpx;
		height: 32rpx;
	}
	.appTab { // 标题组件兼容ios
		display: flex;
		align-items: center;
		padding: 0 28rpx;
		background-color: #2583DA;
		color: #fff;
		font-size: 32rpx;
		position: fixed;
		left: 0;
		top: 0;
		width: 100%;
		height: 88rpx;
		height: calc(88rpx + constant(safe-area-inset-top));
		height: calc(88rpx + env(safe-area-inset-top));
		padding: 14rpx 0px;
		padding-top: calc(14rpx + constant(safe-area-inset-top));
		padding-top: calc(14rpx + env(safe-area-inset-top));
		display: -webkit-box;
		display: -webkit-flex;
		overflow: hidden;
		-webkit-box-pack: justify;
		-webkit-justify-content: space-between;
		justify-content: space-between;
		box-sizing: border-box;
		z-index: 995;
		-webkit-transition-property: all;
		transition-property: all;
	}
	.iswxh5 .appTab{
		position: absolute!important;
	}
	.text-center {
		text-align: center;
	}
	.text-right {
		text-align: right;
	}
	.text-left {
		text-align: left;
	}
	.flex-start {
		display:flex;
		display: -webkit-flex;
		justify-content:flex-start;
		-webkit-justify-content:flex-start;
	}
	.flex-end {
		display:flex;
		display: -webkit-flex;
		justify-content:flex-end;
		-webkit-justify-content:flex-end;
	}
	.flex-between {
		display:flex;
		display: -webkit-flex;
		justify-content:space-between;
		-webkit-justify-content:space-between;
	}
	.flex-column {
		display:flex;
		display: -webkit-flex;
		flex-direction: column;
	}
	.flex-center {
		display:flex;
		display: -webkit-flex;
		justify-content:center;
		-webkit-justify-content:center;
		align-items: center;
		-webkit-align-items: center;
	}
	.algin-center{align-items: center;}
	@for $i from 0 through 120 {  // margin,padding 0-120样式
		// 只要双数和能被5除尽的数
		@if $i % 2 == 0 or $i % 5 == 0 {
			// 得出：u-m-30，u-mt-30
			.u-m-#{$i} {
				margin: $i + rpx;
			}
			.u-mt-#{$i} {
				margin-top: $i + rpx;
			}
			.u-mr-#{$i} {
				margin-right: $i + rpx;
			}
			.u-mb-#{$i} {
				margin-bottom: $i + rpx;
			}
			.u-ml-#{$i} {
				margin-left: $i + rpx;
			}
			.u-mlr-#{$i} {
				margin-left: $i + rpx!important;
				margin-right: $i + rpx!important;
			}
			.u-mtb-#{$i} {
				margin-top: $i + rpx!important;
				margin-bottom: $i + rpx!important;
			}
			// 得出：u-padding-30或者u-p-30
			.u-p-#{$i} {
				padding: $i + rpx;
			}
			.u-pt-#{$i} {
				padding-top: $i + rpx;
			}
			.u-pr-#{$i} {
				padding-right: $i + rpx;
			}
			.u-pb-#{$i} {
				padding-bottom: $i + rpx;
			}
			.u-pl-#{$i} {
				padding-left: $i + rpx;
			}
			.u-plr-#{$i} {
				padding-left: $i + rpx!important;
				padding-right: $i + rpx!important;
			}
			.u-ptb-#{$i} {
				padding-top: $i + rpx!important;
				padding-bottom: $i + rpx!important;
			}
		}
	}
	// @media screen and (min-width:	10px) and (max-width:	340px){.smallMargin{margin-left:3%!important}}
	//顶部搜索栏
	/* #ifndef APP-NVUE */
		page {
			display: flex;
			flex-direction: column;
			box-sizing: border-box;
			background-color: #fafafa;
			min-height: 100%;
			height: auto;
		}
		view {
			font-size: 14px;
			line-height: inherit;
		}
		.example-body {
			/* #ifndef APP-NVUE */
			display: flex;
			/* #endif */
			flex-direction: row;
			flex-wrap: wrap;
			justify-content: center;
			padding: 0;
			font-size: 14px;
			// background-color: #ffffff;
		}
		/* #endif */
		.example-info-text {
			font-size: 14px;
			line-height: 20px;
			color: #3b4144;
		}
		.example-body {
			flex-direction: column;
			padding: 15px;
			background-color: #ffffff;
		}
		.word-btn-white {
			font-size: 18px;
			color: #FFFFFF;
		}
		.word-btn {
			/* #ifndef APP-NVUE */
			display: flex;
			/* #endif */
			flex-direction: row;
			align-items: center;
			justify-content: center;
			border-radius: 6px;
			height: 48px;
			margin: 15px;
			background-color: #007AFF;
		}
		.word-btn--hover {
			background-color: #4ca2ff;
		}
		.uni-nav-bar-text {
			font-size: 15px;
			text-overflow: ellipsis;
			overflow: hidden;
			white-space: nowrap;
		}
		.city {
			/* #ifndef APP-PLUS-NVUE */
			display: flex;
			/* #endif */
			flex-direction: row;
			align-items: center;
			// justify-content: flex-start;
			 width: 120rpx;
			// margin-left: 4px;
			// border: 1px solid;
		}
		.input-view {
			/* #ifndef APP-PLUS-NVUE */
			display: flex;
			/* #endif */
			flex-direction: row;
			 // width: 400rpx;
			flex: 1;
			background-color: #fff;//#f8f8f8
			height: 30px;
			border-radius: 15px;
			padding: 0 15px;
			flex-wrap: nowrap;
			margin: 7px 0;
			line-height: 30px;
			// border: 1px solid red;
		}
		.input-uni-icon {
			line-height: 30px;
		}
		.nav-bar-input {
			height: 30px;
			line-height: 30px;
			/* #ifdef APP-PLUS-NVUE */
			width: 370px;
			/* #endif */
			width: 308rpx;//输入框的宽度
			padding: 0 5px;
			font-size: 12px;
			background-color: #fff;//#f8f8f8
		}
		.example-body {
			/* #ifndef APP-NVUE */
			display: block;
			/* #endif */
			padding: 0;
		}
</style>
